package com.yboot.starter.holiday.config;

import com.yboot.starter.api.core.cache.CacheService;
import com.yboot.starter.holiday.core.HolidayDataStorageService;
import com.yboot.starter.holiday.core.impl.DefaultHolidayManageImpl;
import com.yboot.starter.holiday.core.HolidayManage;
import com.yboot.starter.holiday.core.impl.DefaultHolidaySynchronizer;
import com.yboot.starter.holiday.core.HolidaySynchronizerService;
import com.yboot.starter.holiday.core.impl.HolidayDataStorageServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 功能描述
 *
 * @author yangcs
 * @date 2025/8/8
 */
@Configuration
public class HolidayAutoConfigure {

    @Value("${holiday.onlineUrl:https://api.jiejiariapi.com/v1/holidays/}")
    private String onlineUrl;

    @Bean
    @ConditionalOnMissingBean
    public HolidaySynchronizerService holidaySynchronizer() {
        return new DefaultHolidaySynchronizer(onlineUrl);
    }

    @Bean
    @ConditionalOnMissingBean
    public HolidayDataStorageService holidayDataStorageService(CacheService cacheService) {
        return new HolidayDataStorageServiceImpl(cacheService);
    }
    @Bean
    @ConditionalOnMissingBean
    public HolidayManage holidayManage(HolidaySynchronizerService holidaySynchronizerService,
                                       HolidayDataStorageService holidayDataStorageService) {
        return new DefaultHolidayManageImpl(holidaySynchronizerService, holidayDataStorageService);
    }
}
